package prova;

import java.io.ObjectInputStream.GetField;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.geom.PrecisionModel;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
import com.vividsolutions.jts.operation.polygonize.Polygonizer;

public class Test {
	
	
	public static void codGeom(){
		
		
		
		// SET DELLA PRIMA GEOMETRIA POLIGONO;
		
		Geometry g1 = polygons();
	
		
		// SET DELLA SECONDA GEOMETRIA	
		/*ListaCoordinate ls = new ListaCoordinate();
		ArrayList <double[]>al = new ArrayList();
		al = ls.getCoordinate(45.956272 , 10.908161);
		
		double[] prova = al.get(0);
	
		Coordinate coordinates1 = new Coordinate( prova[0] , prova[1]);	
		
		Geometry g2 = new GeometryFactory().createPoint(coordinates1);*/
		
		
		
		
		//TEST CONTAIN E WITHIN 
		
	/*	System.out.println(g1);
		System.out.println(g2);
		

		boolean test = g1.contains(g2);
		boolean test2 = g2.within(g1);

		
		System.out.println(test);
		System.out.println(test2);*/

		
	}
	
	
	// METODO CHE CREA UN POLIGONO
	public static Polygon polygons(){
		WKTReader reader = new WKTReader();
		Polygonizer polygonizer = new Polygonizer();
		Collection<Geometry> lines = new ArrayList();
		Collection polys = null;
		Polygon p = null;
	
		
		try {
			/*lines.add(reader.read("LINESTRING (45.955897 10.908403 , 45.956433 10.908758)"));
			lines.add(reader.read("LINESTRING (45.956433 10.908758, 45.956669 10.907986)"));    //dangling edge
			lines.add(reader.read("LINESTRING (45.956669 10.907986, 45.956169 10.907664)"));
			lines.add(reader.read("LINESTRING (45.956169 10.907664, 45.955897 10.908403)"));*/
			String prova = "LINESTRING (45.956661 10.907986, 45.956169 10.907664, 45.937664 10.908015 , 45.955897 10.908403 , 45.956433 10.908758, 45.956661 10.907986)";
			System.out.println(prova);
			lines.add(reader.read(prova));
			polygonizer.add(lines);
			polys   = polygonizer.getPolygons();
			System.out.println("polys size"+polys.size());
			Iterator i = polys.iterator();
			while(i.hasNext()){
				p = (Polygon) i.next();
			}
			System.out.println("l:" +polygonizer.getPolygons());
			System.out.println("p "+p);
			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}    // isolated edge
		
		return p;
		
	
	}
	
	//METODO CHE CREA UNA COLLEZIONE DI POLIGONI
	
	/*public static Collection<Polygon> polygonsCollection(){
		WKTReader reader = new WKTReader();
		Polygonizer polygonizer = new Polygonizer();
		Collection lines = new ArrayList();
		Collection polys = null;
		Polygon p = null;
		try {
			lines.add(reader.read("LINESTRING (45.955897 10.908403 , 45.956433 10.908758)"));
			lines.add(reader.read("LINESTRING (45.956433 10.908758, 45.956669 10.907986)"));    //dangling edge
			lines.add(reader.read("LINESTRING (45.956669 10.907986, 45.956169 10.907664)"));
			lines.add(reader.read("LINESTRING (45.956169 10.907664, 45.955897 10.908403)"));
			polygonizer.add(lines);
			polys   = polygonizer.getPolygons();
			
			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}    // isolated edge
		
		return  polys;
	}*/
// METODO CHE CREA LA LISTA DI COPPIE DI COORDINATE PER OGNI SEGMENTO DI OGNI POLIGONO
	//public static void creaListaStringhe(){}
	
// METODO CHE CREA LA LISTA DI STRINGHE PER OGNI POLIGONO 
	//public static void creaListaStringhe(){}
	
	/**
	 * @param args
	 */
	/*public static void main(String[] args) {
	codGeom();
		

	}*/

}
